-
-
Notifications
You must be signed in to change notification settings - Fork 197
West Midlands | ITP-Sept-25 | Mustaf Asani | Sprint 2 | Data groups coursework #934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
West Midlands | ITP-Sept-25 | Mustaf Asani | Sprint 2 | Data groups coursework #934
Conversation
…n implement folder
…works as expected
…in querystring test suite
in querystring file and refactored tally.js to use itemcount
cjyuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are doing great. tally.js could still use some improvement.
Sprint-2/implement/tally.js
Outdated
| let n = 0; | ||
|
|
||
| while (inputArray.length > 0) { | ||
| itemCount = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
itemCount is used only inside the while loop, so it is best practice to declare the variable here (in the block { ... } where the variable is being used)
Sprint-2/implement/tally.js
Outdated
|
|
||
| while (inputArray.length > 0) { | ||
| itemCount = 0; | ||
| const tempArray = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can your code work without using tempArray?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i realised the danger of nested while loops that rely on internally changing variables, when i changed to remove tempArray as its value was no longer being used, I came across an endless loop as my original one was relying on taking out items from inputArray to give an exit condition. I refactored my code to use an iterator to count the frequency of each item without mutating inputArray.
Sprint-2/implement/tally.js
Outdated
| i--; | ||
| } | ||
|
|
||
| if (itemCount > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this check necessary? Under what circumstances will itemCount be 0 or less?
…of items in an array.
cjyuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous solution was not as efficient but it was a good opportunity to practice using nested loops.
I will go ahead and approve this PR first, you can improve your solution later.
| throw new Error("error invalid input passed, please provide an array"); | ||
| } | ||
|
|
||
| const tallyObject = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the following function call returns the value you expect?
tally(["toString", "toString"]);
Suggestion: Look up an approach to create an empty object with no inherited properties.
Learners, PR Template
Self checklist
Changelist
Completed the debug, implement and interpret tasks